<template>
  <div class="box-container">
    <!-- 导航栏 -->
    <div @click="close">
      <van-nav-bar title="我的频道           点击返回" style="background-color:pink">
        <!-- <template #right>
        <van-icon name="cross" size="0.37333334rem" color="white" @click="close" />
      </template> -->
      </van-nav-bar>
    </div>

    <!-- 我的频道 -->
    <div class="my-channel-box">
      <div class="channel-title">
        <span> 我的频道
          <span class="small-title">
            {{ isEdit ? "点击删除频道" : "点击进入频道" }}
          </span>
        </span>
        <span @click="isEdit = !isEdit">
          {{ isEdit ? "编辑" : "完成" }} -->
        </span>
      </div>
      <!-- 我的频道列表 -->
      <van-row type="flex" class="myChannel">
        <van-col span="6" v-for="item in userChannelList" :key="item.id" @click="deleteChannel(item)">
          <div class="channel-item van-hairline--surround">
            {{ item.name }}
            <!-- 删除的徽标 -->
            <van-badge color="transparent" class="cross-badge" v-show="isEdit && item.id !== 0">
              <template #content>
                <van-icon name="cross" class="badge-icon" color="#cfcfcf" size="0.32rem" />
              </template>
            </van-badge>
          </div>
        </van-col>
      </van-row>
    </div>

    <!-- 更多频道 -->
    <div class="more-channel-box">
      <div class="channel-title">
        <span>点击添加更多频道：</span>
      </div>
      <!-- 更多频道列表 -->
      <van-row type="flex">
        <van-col span="6" v-for="item in unCheckChannelList" :key="item.id" @click="addChannel(item)">
          <div class="channel-item van-hairline--surround">{{ item.name }}</div>
        </van-col>
      </van-row>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    userChannelList: Array,
    unCheckChannelList: Array
  },
  emits: ['addChannelFn', 'deleteChannelFn', 'closeFn', 'changeChannel'],
  data() {
    return {
      isEdit: true,
      isShow: true
    }
  },
  methods: {
    // 增加频道传参
    addChannel(channelObj) {
      if (this.isEdit === true) {
        this.$emit('addChannelFn', channelObj)
      }
    },
    // 删除频道传参
    deleteChannel(channelObj) {
      if (this.isEdit === true) {
        if (channelObj.id !== 0) {
          // 满足两个条件才可删除，但两个不能并列写，思考下为什么
          this.$emit('deleteChannelFn', channelObj)
        }
      } else {
        // 点击进入该频道
        this.$emit('closeFn')
        this.$emit('changeChannel', channelObj)
      }
    },
    // 关闭弹出层方法
    close() {
      this.$emit('closeFn')
      this.isEdit = true
    }
  }
}
</script>

<style lang="less" scoped>
.my-channel-box,
.more-channel-box {
  .channel-title {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    line-height: 28px;
    padding: 0 6px;
  }
}

.channel-item {
  font-size: 12px;
  text-align: center;
  line-height: 36px;
  background-color: #fafafa;
  margin: 5px;
}

/*删除的微标 */
.cross-badge {
  position: absolute;
  right: -3px;
  top: 0;
  border: none;
}

/*提示文字 */
.small-title {
  font-size: 10px;
  color: gray;
}
</style>
